<template>
	<view>
		<view v-if="identityType == 1" class="order-header margin-bottom_10">
			<info identity="identityType" :infoData="distributor" size="100"></info>
		</view>

		<shop-list :shopList="list" size="100" @details="shopDetails"></shop-list>
		<view class="loading">
			<block v-if="isLoading">
				<image src="https://mall.xzthealth.com/loading2.gif"></image>
				<text>加载中</text>
			</block>
		</view>
		<without v-if="!isLoading" :showImg="false" :tip="tip"></without>
	</view>
</template>

<script>
import info from '@/components/info.vue';
import shopList from '@/components/shop-list.vue';
import without from '@/components/without.vue';
import { distributeOrder } from '@/mixins/index.js';
import { store, mutations } from '@/store/index.js';
export default {
	mixins: [distributeOrder],
	// 依赖注入
	provide: {
		size: 100
	},
	components: {
		info,
		shopList,
		without
	},

	data() {
		return {
			list: [],
			page:1,
			limit:10,
			count:0,
			isLoading:true,
			tip:'暂无数据',
			identityType: 0 //{1我的分销员，2我的客户}
		};
	},

	computed: {
		distributor() {
			console.log('store.info',store.info)
			return store && store.info;
		},
		distributor_id() {
			return store && store.distributor_id;
		}
	},
	onLoad(options) {
		console.log(options);
		this.identityType = Number(options.identityType);
		if (this.identityType === 1) {
			// 我的分销员订单
			// {specified:"分销员id",type:'1'}
			console.log('分销员订单 distributor_id',this.distributor)
			this.getDistributionOrder({
				specified:this.distributor['distributor_id'],
				type:'1'
			});

		} else {
			// 我的客户订单
			uni.setNavigationBarTitle({
				title: '客户订单'
			});
			// {specified:"客户id",type:'2'}
			this.getDistributionOrder({
				specified:this.distributor['uid'],
				type:'2'
			});
		}
	},
	methods: {
		shopDetails(id){
			let distributor_id = this.distributor_id
			uni.navigateTo({
				url:'/pages/product/details/details?id='+id+'&distributor_id='+distributor_id
			})
		}
	},
	onReachBottom() {
		if (this.count > this.list.length) {
			this.isLoading = true;
			this.page++;
			if (this.identityType === 1) {
				this.getDistributionOrder({
					specified:this.distributor['distributor_id'],
					type:'1'
				});
			} else {
				this.getDistributionOrder({
					specified:this.distributor['uid'],
					type:'2'
				});
			}
		} else {
			this.tip = '已加载全部';
		}
	}
};
</script>

<style lang="less">
@import '@/common/index.less';
page {
	background-color: #f6f6f6;
	box-sizing: border-box;
	padding: 15rpx 25rpx;
}
.order-header {
	background: #fff;
	padding: 15rpx;
	border-radius: 8px;
}
</style>
